﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Configuration;
using System.Windows.Forms;
using System.ServiceProcess;


namespace Com.Oxilly.Qsb.Services
{
    [RunInstaller(true)]
    public partial class ProjectInstaller : System.Configuration.Install.Installer
    {
        public ProjectInstaller()
        {
            InitializeComponent();
        }

        public override void Commit(IDictionary savedState)
        {
            String exePath = this.Context.Parameters["assemblypath"];
            String QBUSHOST = this.Context.Parameters["qbushost"];
            String QBUSUSER = this.Context.Parameters["qbususer"];
            String QBUSPASS = this.Context.Parameters["qbuspass"];

            //String QBUSHOST = savedState["QBUSHOST"] as String;
            //String QBUSUSER = savedState["QBUSUSER"] as String;
            //String QBUSPASS = savedState["QBUSPASS"] as String;

            Configuration config = ConfigurationManager.OpenExeConfiguration(exePath);

            config.AppSettings.Settings["QBUSHOST"].Value = QBUSHOST;
            config.AppSettings.Settings["QBUSUSER"].Value = QBUSUSER;
            config.AppSettings.Settings["QBUSPASS"].Value = QBUSPASS;

            config.Save();
         

            base.Commit(savedState);
        }

        public override void Install(IDictionary savedState)
        {
          
            
            base.Install(savedState);

          
        }

        private void qsbServiceInstaller_AfterInstall(object sender, InstallEventArgs e)
        {
            ServiceController service = new ServiceController(this.qsbServiceInstaller.ServiceName);
            service.Start();
        }

    }
}
